﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Windows.Forms;
using CharacterTrailLibrary.Factory;
using CharacterTrailLibrary.Impl;
using CharacterTrailLibrary.Interface;
using CharacterTrailLibrary.Persist;

namespace CharacterTrailClient.Core
{
    public class AppInitializer
    {
        public static bool UsingGridStyleSaving = false;
        public static FormMain MainForm = null;
        public static void InitializeApp()
        {
            IUserLoader loader = InstanceFactory.GetUserLoader();
            CharacterTrailLibrary.Security.UserSession.CurrentUser.UserId = loader.GetUserId();
            CharacterTrailLibrary.Security.UserSession.CurrentUser.UserName = loader.GetUserName();
            DAHelper.SqlConnectionString = loader.GetSqlConnectionString();
            if(File.Exists(Application.StartupPath+ "\\usingGridStyleSaving.txt"))
            {
                UsingGridStyleSaving = true;
            }
        }

        public static void InitializeRegisterThreadException()
        {
            Application.ThreadException += Application_ThreadException;
        }

        private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
        {
            Message.MsgBox.ShowError(MainForm, e.Exception.Message);
        }
    }
}
